<?php

namespace app\admin\model;

class TieBaComment extends \app\common\model\TieBaComment
{
    /**
     * 列表
     * @param $tieId
     * @return array
     * @throws \think\exception\DbException
     */
    public static function getList($tieId)
    {
        $sql = static::field('id, from_nickname, content, is_reply, create_time')
            ->where(['tie_id' => $tieId]);

        $data = $sql->paginate(null, false, ['query' => request()->param()]);

        $model = $data->each(function ($item, $key) {
            $item['create_time'] = get_datetime($item['create_time']);
            $item['is_reply'] = self::attributes('is_reply', $item['is_reply']);
            return $item;
        });

        // 获取总记录数
        $count = $model->total();
        return [
            'model' => $model,
            'count' => $count
        ];
    }

    public static function deleteAll($ids)
    {
        static::where('id', 'in', $ids)->delete();
    }

    public static function deleteByTie($tieIds)
    {
        static::where('tie_id', 'in', $tieIds)->delete();
    }

    /**
     * 获取帖子评论数量
     */
    public static function getCountByTie($tieId){
        return static::where(['tie_id' => $tieId])->count();
    }
}